package date1023;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

/**
 * @Author: huhx
 * @Date: 2017-10-23 下午 4:50
 */
public class GenerateUtils {
    // 将user_name转换成userName的写法
    public static String getWithHumpContent(String string) {
        string = transOtherLetterLower(string);
        String resultString = string;
        Pattern pattern = Pattern.compile("_(.)");
        Matcher matcher = pattern.matcher(string);
        String result = "";
        while (matcher.find()) {
            result = matcher.group(1);
            resultString = string.replace("_" + result, result.toUpperCase());
        }
        return resultString;
    }

    // 首字母不变，其他字母转换成小写
    public static String transOtherLetterLower(String string) {
        String str = string.substring(1);
        return string.replaceFirst(str, str.toLowerCase());
    }

    // 将首字母小写
    public static String transforFirstLetterLower(String string) {
        String str = string.substring(0, 1);
        return string.replaceFirst(str, str.toLowerCase());
    }
}
